﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class TreeNode
{
    public int val;
    public TreeNode left;
    public TreeNode right;
    public TreeNode(int val = 0, TreeNode left = null, TreeNode right = null)
    {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

namespace PrimaryAlgorithm.MaxDepth
{
    class Mainproject
    {
        static void Main(string[] args)
        {
            TreeNode treeNode = new TreeNode(3,new TreeNode(9),new TreeNode(20,new TreeNode(15),new TreeNode(17)));
            Console.WriteLine(MaxDepth(treeNode));
            Console.ReadKey();
        }
        //二叉树的最大深度
        public static int MaxDepth(TreeNode root)
        {
            if (root==null)
                return 0;
            return Math.Max(MaxDepth(root.left), MaxDepth(root.right)) + 1;
        }
    }
}
